<template>
  <!--商品描述-->
  <div v-if="editDialogVisible4">
    <el-tabs v-model="activeName" type="card" @tab-click="handleClick2">
      <el-tab-pane label="商品描述" name="first" >
<!--    <el-row :gutter="24">-->
<!--      <el-col :span="2">-->
<!--        <el-upload :action="imgUpload" :before-upload="beforeAvatarUpload" :on-success="handleSuccessDescribe"  v-model="describeDataForm.pictureUrl" accept="image/gif, image/jpeg, image/jpg, image/png" >-->
<!--          <el-button  size="mini" type="primary">上传图片</el-button>-->
<!--       </el-upload>-->
<!--      </el-col>-->
<!--       <el-col :span="8">-->
<!--        <p><span class="ng-binding">支持4M及以下的jpg、jpeg、png、gif格式图片</span></p>-->
<!--      </el-col>-->
<!--   </el-row>-->

          <div ng-repeat="e in merchantProductPic" style="margin-left: 15px;margin-top: 20px;" v-for="(item ,i) in fileListDescribeCopy" :key="i">
            <img  style="height: 200px;width: 200px;display: block" :src="item.url" />
          </div>

      </el-tab-pane>
      <el-tab-pane label="温馨提示" name="second">

<!--    <el-row :gutter="24">-->
<!--      <el-col :span="2">-->
<!--         <el-upload :action="imgUpload" :before-upload="beforeAvatarUpload"  :on-success="handleSuccessTips" v-model="tipsDataForm.pictureUrl" accept="image/gif, image/jpeg, image/jpg, image/png" >-->
<!--          <el-button size="mini" type="primary">上传图片</el-button>-->
<!--      </el-upload>-->
<!--      </el-col>-->
<!--       <el-col :span="8">-->
<!--        <p><span class="ng-binding">支持4M及以下的jpg、jpeg、png、gif格式图片</span></p>-->
<!--      </el-col>-->
<!--   </el-row>-->


         <div ng-repeat="e in merchantProductPic" style="margin-left: 15px;margin-top: 20px;" v-for="(item ,i) in fileListTipsCopy" :key="i">
            <img  style="height: 200px;width: 200px;display: block" :src="item.url" />
          </div>
      </el-tab-pane>
      <el-tab-pane label="价格说明" name="third">
        <img  style="height: 40%;width: 40%;display: block" src="http://40.73.68.11:8095/images/20200819/20200819_73901d34d8a62b50a91e7ff2d9ac6c5f.jpg" />
      </el-tab-pane>
      <!--<el-tab-pane label="PC商品描述" name="second"></el-tab-pane>-->
    </el-tabs>





    <el-form>
      <el-form-item class="styleReplace3" prop="content">
        <el-upload class="avatar-uploader" :action="imgUpload" multiple :on-success="uploadSuccess" :show-file-list="false" >
        </el-upload>
        <quill-editor v-model="dataFormDescribe.content" ref="myTextEditor" style="height: 300px;" :options="editorOption" ></quill-editor>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer" style="text-align:center;margin-top:80px">
      <el-button :size="size" type="primary" @click.native="submitFormDescribe" :loading="editLoading">{{ $t("action.submit") }} </el-button>
    </div>



  </div>

</template>

<script>
import CyTable from "@/views/Core/CyTable";
import KtButton from "@/views/Core/KtButton";
import { format, formatDate } from "@/utils/datetime";
import TableColumnFilterDialog from "@/views/Core/TableColumnFilterDialog";
import { quillEditor } from "vue-quill-editor";
import "quill/dist/quill.core.css";
import "quill/dist/quill.snow.css";
import "quill/dist/quill.bubble.css";
const toolbarOptions = [
  ["bold", "italic", "underline", "strike"],
  ["blockquote", "code-block"],
  [{ header: 1 }, { header: 2 }],
  [{ list: "ordered" }, { list: "bullet" }],
  [{ script: "sub" }, { script: "super" }],
  [{ indent: "-1" }, { indent: "+1" }],
  [{ direction: "rtl" }],
  [{ header: [1, 2, 3, 4, 5, 6, false] }],
  [{ color: [] }, { background: [] }],
  [{ align: [] }],
  ["link", "image"],
  ["clean"]
];
export default {
  components: {
    KtButton,
    CyTable,
    TableColumnFilterDialog,
    quillEditor
  },
  data() {
    return {
      imgUpload: this.utils.imgUploadUrl, //上传
      fileListDescribe: [],
      fileListDescribeCopy: [],
      fileListTips: [],
      fileListTipsCopy: [],
      size: "small",
      editDialogVisible4: false,
      activeName: "first",
      describeDataForm: {
        pictureUrl: "",
        documentLicense: ""
      },
      tipsDataForm: {
        pictureUrl: "",
        documentLicense: ""
      },
      editorOption: {
        theme: "snow",
        boundary: document.body,
        modules: {
          toolbar: {
            container: toolbarOptions, //
            handlers: {
              image: function(value) {
                if (value) {
                  document.querySelector(".avatar-uploader input").click();
                } else {
                  this.quill.format("image", false);
                }
              }
            }
          }
        },
        placeholder: "请输入协议内容",
        readOnly: false
      },
      dataFormDescribe: {
        content: "",
        type: 0,
        id: 0
      },
      editLoading: false,
      productId: 0
    };
  },
  mounted() {},
  methods: {
    //富文本图片插入
    uploadSuccess(res, file) {
      // 首先获取富文本编辑器的实例
      let quill = this.$refs.myTextEditor.quill;
      // 上传成功所执行
      if (res.code == "0000" && res.data !== null) {
        // 获取光标所在位置
        let length = quill.getSelection().index;
        // 插入图片res为服务器返回的数据
        quill.insertEmbed(length, "image", res.data.imgUrl);
        // 光标移动至文本末端
        quill.setSelection(length + 1);
      } else {
        this.$message.error("图片插入失败");
      }
    },
    //校验上传的文件的大小
    beforeAvatarUpload(file) {
      const isLt2M = file.size / 1024 / 1024 < 4;
      if (!isLt2M) {
        this.$message.error("上传头像图片大小不能超过 4MB!");
      }
      return isLt2M;
    },
    // 商品描述图片上传
    handleSuccessDescribe: function(res, file) {
      this.fileListDescribe = [];
      let imgUrl = {};
      imgUrl.url = res.data.imgUrl;
      this.fileListDescribeCopy.push(imgUrl);
    },
    //图片移除
    handleRemove(file, fileList, index) {
      if (this.utils.isNull(index)) {
        this.fileListSale = fileList;
        if (fileList.length == 0) {
          this.dataForm.pictureUrl = "";
        } else {
          this.imgs = fileList
            .map(item => item.response.data.imgUrl)
            .toString();
          this.dataForm.documentLicense = this.imgs;
        }
      } else {
        this.bill_photo_list.splice(index, 1);
      }
      console.log(this.dataForm.document_license);
    },
    // 商品温馨提示上传
    handleSuccessTips: function(res, file) {
      this.fileListTips = [];
      let imgUrl = {};
      imgUrl.url = res.data.imgUrl;
      this.fileListTipsCopy.push(imgUrl);
    },
    init(param) {
      this.editDialogVisible4 = param.flag;
      this.productId = param.productId;
      if (param.flag) {
        param.type = 0;
        this.queryProductDescribe(param);
      }
    },
    handleClick2(tab) {
      let this_ = this;
      if (tab.name === "first") {
        this_.activeName = "first";
      }
      if (tab.name === "second") {
        this_.activeName = "second";
      }
      if (tab.name === "third") {
        this_.activeName = "third";
      }
      /* else {
        this.dataFormDescribe.content = "";
        this.dataFormDescribe.type = 1;
        //商品PC描述
        let param = {};
        param.productId = this.productId;
        param.type = 1;
        this.queryProductDescribe(param);
      } */
    },
    queryProductDescribe(param) {
      let this_ = this;
      this.utils.request.queryProductDescribe(param, function(data) {
        if (data.data != null) {
          $.each(data.data, function(index, val) {
            this_.dataFormDescribe = val;
          });
        }
      });
    },
    submitFormDescribe: function() {
      this.$confirm("确认提交吗？", "提示", {}).then(() => {
        let this_ = this;
        let paramsForm = {};
        paramsForm.productId = this_.productId;
        paramsForm.content = this_.dataFormDescribe.content;
        paramsForm.type = this_.dataFormDescribe.type;
        paramsForm.id = this_.dataFormDescribe.id;
        this.utils.request.addOrUpdateProductDescribe(paramsForm, function(
          res
        ) {
          if (res.code == "0000") {
            this_.dataFormDescribe.id = res.data.id;
            this_.$message({ message: "操作成功", type: "success" });
          } else {
            this_.$message({
              message: "操作失败, " + res.msg,
              type: "error"
            });
          }
        });
      });
    }
  }
};
</script>

<style scoped>
</style>
